package com.dhcy.mqtt.time;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dhcy.mqtt.dao.RevEquipmentDataMapper;
import com.dhcy.mqtt.model.RevEquipmentData;
import com.dhcy.mqtt.service.RevEquipmentDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author han
 * @Date 2022/3/17
 * @apiNote
 */
@Slf4j
@Component
public class EquipmentPushTimerSche {


    @Autowired
    private RevEquipmentDataService revEquipmentDataService;

//    @Scheduled(cron = "0 */5 * * * ?")
    void pushEquipment(){
        List<RevEquipmentData> equipmentData = revEquipmentDataService.getBaseMapper().selectList(new QueryWrapper<RevEquipmentData>().eq("is_push", 0));
        if (ObjectUtil.isNotEmpty(equipmentData)){
            equipmentData.stream().forEach(item->{
                boolean b = revEquipmentDataService.equipmentPush(item);
                log.info("推送数据{}结果为"+b, JSONUtil.toJsonStr(item));
            });
        }
    }
}
